﻿using ClickHouse.EntityFrameworkCore.Extensions;
using Microsoft.EntityFrameworkCore;
using NanjingbeiRailwayStation.Core;
using NanjingbeiRailwayStation.Data.ClickHouse.Entities;

namespace NanjingbeiRailwayStation.Data.ClickHouse
{


    public class Db : DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);

            optionsBuilder.UseClickHouse(StringConstant.ClickHouseConnectionString);

        }

     

        /// <summary>
        /// 实时电参数
        /// </summary>

        public DbSet<RealTimeElectricalParameters> RealTimeElectricalParameters { get; set; }

        /// <summary>
        /// 事件上报
        /// </summary>
        public DbSet<EventReport> EventReport { get; set; }

        /// <summary>
        /// 设备
        /// </summary>
        public DbSet<DeviceEntity>  DeviceEntitie { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="modelBuilder"></param>
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);


            var deviceEntityBuilder = modelBuilder.Entity<DeviceEntity>();

            deviceEntityBuilder.HasNoKey();

            var eventReportBuilder = modelBuilder.Entity<EventReport>();

            eventReportBuilder.HasNoKey();

            var realTimeElectricalParametersBuilder = modelBuilder.Entity<RealTimeElectricalParameters>();

            realTimeElectricalParametersBuilder.HasNoKey();


        }


    }
}
